<?php defined('SYSPATH') or die('No direct script access.');

abstract class Controller extends Kohana_Controller {
	
	public $view;
	protected $url_root;
	protected $doc_root;
	protected $static_root;
	protected $remote_root;
	protected $language;
	
	public function __construct(Request $request, Response $response) {
		
		parent::__construct($request, $response);
		// Set the language with URI
		$language = "";
		if(Arr::get(Kohana::modules(), "i18nUrl")) {
			$this->language = I18n::lang()."/";
		}
		define("DOC_ROOT", $this->doc_root = Kohana::$base_url);
		define("URL_ROOT", $this->url_root = $this->doc_root.$this->language);
		define("STATIC_ROOT", $this->static_root = Kohana::$config->load('dec')->static_root);
        define("REMOTE_ROOT", $this->remote_root = Kohana::$config->load('dec')->remote_root);
		$smarty = new Smarty_View;
		$smarty->bind_global("URL_ROOT", $this->url_root); 
		$smarty->bind_global("DOC_ROOT", $this->doc_root); 
		$smarty->bind_global("STATIC_ROOT", $this->static_root); 
        $smarty->bind_global("REMOTE_ROOT", $this->remote_root);
	}
        
        public function logged_in_area(){
            if(!Model_User::logged_in(Kohana::$config->load("grademagica")->webuser_role_name)) {
                $redirect = '';
//                die($this->request->uri());
//                die('!'.$this->request->uri().'!');
                if($this->request->uri()!='/' && $this->request->uri()!='cadastro'){
                    $redirect = '?redirect='.$this->request->uri();
                }
//                $this->request->redirect();
                $this->request->redirect($this->language."cadastro".$redirect);
            }
        }
	
} // End Controller